// contracts/suppler.go
package contracts

import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/google/uuid"
	"github.com/hyperledger/fabric-contract-api-go/contractapi"
	"soa/contracts/model"
	"strconv"
	"strings"
	"time"
)

// 实例化对象
type MallContract struct {
	contractapi.Contract
}

// 默认头像 商家注册之后默认头像
const HEAD = "../assets/images/head.jpg"

// 商家用户注册
func (m *MallContract) SupplierRegister(ctx contractapi.TransactionContextInterface, email string, pass string) (bool, error) {
	exists, err := m.SupplerExists(ctx, email)
	if err != nil || exists == false {
		return false, err
	}
	//创建一个新商家对象
	new_suppler := model.SupplierUser{
		Email: email,
		Pass:  pass,
		Head:  HEAD, //注册后使用默认头像 后期可以自己更换
	}

	//将数据json化
	marshal, err := json.Marshal(new_suppler)
	if err != nil {
		return false, err
	}

	//将商家以email为键上传状态
	err = ctx.GetStub().PutState("o_"+email, marshal)
	if err != nil {
		return false, err
	}

	//获取商家数组
	supplier_bytes, err := ctx.GetStub().GetState("suppliers")
	if err != nil {
		return false, err
	}

	var SUPPLIER []model.SupplierUser
	err = json.Unmarshal(supplier_bytes, &SUPPLIER)
	if err != nil {
		return false, err
	}

	SUPPLIER = append(SUPPLIER, new_suppler)
	bytes, err := json.Marshal(SUPPLIER)
	if err != nil {
		return false, err
	}
	err = ctx.GetStub().PutState("suppliers", bytes)
	if err != nil {
		return false, err
	}

	return true, nil
}

// 实现商家登陆
func (m *MallContract) SupplerLogin(ctx contractapi.TransactionContextInterface, email string, pass string) (bool, error) {
	//判断登陆的商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return false, err //商家不存在 或 查询世界状态失败
	}
	if exists { //代表商家存在
		supplier_bytes, err := ctx.GetStub().GetState("o_" + email) //获取商家信息字节
		if err != nil {
			return false, err
		}
		var supplier_info model.SupplierUser //存储商家信息
		err = json.Unmarshal(supplier_bytes, &supplier_info)
		if err != nil {
			return false, err
		}
		if supplier_info.Pass == pass { //判断商家用户密码是否正确
			return true, nil //代表密码正确
		} else {
			return false, nil //代表密码错误
		}
	}
	return false, nil
}

// 判断商家是否存在
func (m *MallContract) SupplerExists(ctx contractapi.TransactionContextInterface, email string) (bool, error) {
	//获取商家
	state, err := ctx.GetStub().GetState("o_" + email)
	if err != nil {
		return false, fmt.Errorf("failed to read from world state: %v", err)
	}
	return state != nil, nil
}

// 商家实现发布商品
func (m *MallContract) SupplierAddGoods(ctx contractapi.TransactionContextInterface, email, name, pic, desc, price, unit string, stock int) (bool, error) {
	//首先判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return false, err
	}

	if exists { //代表商家存在
		good := model.Good{ //创建一个商品对象
			Id:         uuid.New().String(),
			Name:       name,
			Pic:        pic,
			Desc:       desc,
			Price:      price,
			Stock:      stock,
			Unit:       unit,
			Sales:      0, //创建时销量为0
			Status:     0, //商品等待审核
			CreateTime: time.Now().Format("2006-01-02"),
			Supplier:   email,
		}
		//以商品id为key 商品对象为value 储存进去
		bytes, err := json.Marshal(good)
		if err != nil {
			return false, err
		}
		//储存进去
		err = ctx.GetStub().PutState(good.Id, bytes)
		if err != nil {
			return false, err
		}

		//获取商家的商品列表 然后将新加的商品添加进去
		state, err := ctx.GetStub().GetState("o_" + email)
		if err != nil {
			return false, err
		}

		//实例化商家对象
		var supplier_info model.SupplierUser
		err = json.Unmarshal(state, &supplier_info)
		if err != nil {
			return false, err
		}

		//将新添加的商品添加进去
		supplier_info.Goods = append(supplier_info.Goods, good)

		//在此将数据json化
		marshal, err := json.Marshal(supplier_info)
		if err != nil {
			return false, err
		}

		//更新数据
		err = ctx.GetStub().PutState("o_"+email, marshal)
		if err != nil {
			return false, err
		}

		//获取商家列表
		var GOODS []model.Good
		goods_bytes, err := ctx.GetStub().GetState("goods")
		if err != nil {
			return false, err
		}
		err = json.Unmarshal(goods_bytes, &GOODS)
		if err != nil {
			return false, err
		}

		//将商品添加到总商品列表中
		GOODS = append(GOODS, good)
		//将数据json化
		goodsJson, err := json.Marshal(GOODS)
		if err != nil {
			return false, err
		}
		//将数据存储到世界状态中
		err = ctx.GetStub().PutState("goods", goodsJson)

		//商品id递增

		return true, nil

	} else { //代表商家不存在

		return false, errors.New("supplier user is not exists")
	}
	return false, nil
}

// 商家实现搜索商品
func (m *MallContract) SupplierSearchGoods(ctx contractapi.TransactionContextInterface, email string, search string) ([]model.Good, error) {
	//判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return nil, err
	}

	if exists { //代表商家存在
		//获取商家对象
		state, err := ctx.GetStub().GetState("o_" + email)
		if err != nil {
			return nil, err
		}

		// 实例化商家对象
		var supplier_info model.SupplierUser
		err = json.Unmarshal(state, &supplier_info)
		if err != nil {
			return nil, err
		}

		//存储到搜索到到数据
		var searchResult []model.Good
		// 实现遍历数据
		for _, v := range supplier_info.Goods {
			//从商品名称查看有无匹配
			flag := strings.Contains(v.Name, search)
			if flag { // 代表包含
				searchResult = append(searchResult, v)
			}
		}
		return searchResult, nil
	} else { //代表商家不存在
		return nil, errors.New("supplier user is not exists")
	}
}

// 商家修改商品状态状况
func (m *MallContract) SupplierUpdateGoodsStatus(ctx contractapi.TransactionContextInterface, email string, id string, status int) (bool, error) {
	//判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return false, err
	}

	if exists { //代表商家存在
		//获取商家对象
		state, err := ctx.GetStub().GetState("o_" + email)
		if err != nil {
			return false, err
		}

		// 实例化商家对象
		var supplier_info model.SupplierUser
		err = json.Unmarshal(state, &supplier_info)
		if err != nil {
			return false, err
		}

		var goods model.Good

		// 实现遍历数据
		for k, v := range supplier_info.Goods {
			if v.Id == id {
				supplier_info.Goods[k].Status = status
				goods = supplier_info.Goods[k]
			}
		}

		//在此将数据json化
		marshal, err := json.Marshal(supplier_info)
		if err != nil {
			return false, err
		}

		//更新数据
		err = ctx.GetStub().PutState("o_"+email, marshal)
		if err != nil {
			return false, err
		}

		//修改商品状态
		bytes, err := json.Marshal(goods)
		if err != nil {
			return false, err
		}

		err = ctx.GetStub().PutState(goods.Id, bytes)
		if err != nil {
			return false, err
		}

		//修改所有商品列表的商品
		var GOODS []model.Good
		goods_bytes, err := ctx.GetStub().GetState("goods")
		if err != nil {
			return false, err
		}

		err = json.Unmarshal(goods_bytes, &GOODS)
		if err != nil {
			return false, err
		}

		for k, _ := range GOODS {
			if GOODS[k].Id == id {
				GOODS[k].Status = status
			}
		}

		//上传状态
		goodsJson, err := json.Marshal(GOODS)
		if err != nil {
			return false, err
		}

		err = ctx.GetStub().PutState("goods", goodsJson)

		return true, nil
	} else { //代表商家不存在
		return false, errors.New("supplier user is not exists")
	}
}

// 商家获取商品详情
func (m *MallContract) SupplierGetGoodsDetail(ctx contractapi.TransactionContextInterface, email string, id string) (model.Good, error) {
	//判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return model.Good{}, err
	}

	if exists { //代表商家存在
		//获取商家对象
		state, err := ctx.GetStub().GetState("o_" + email)
		if err != nil {
			return model.Good{}, err
		}

		// 实例化商家对象
		var supplier_info model.SupplierUser
		err = json.Unmarshal(state, &supplier_info)
		if err != nil {
			return model.Good{}, err
		}

		// 实现遍历数据
		for _, v := range supplier_info.Goods {
			if v.Id == id {
				return v, nil
			}
		}
		return model.Good{}, errors.New("good is not exists")
	} else { //代表商家不存在
		return model.Good{}, errors.New("supplier user is not exists")
	}
}

// 删除商品
func (m *MallContract) SupplierDeleteGoods(ctx contractapi.TransactionContextInterface, email string, id string) (bool, error) {
	//判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return false, err
	}

	if exists { //代表商家存在
		//删除商品
		err := ctx.GetStub().DelState(id)
		if err != nil {
			return false, err
		}
		//获取商家对象
		state, err := ctx.GetStub().GetState("o_" + email)
		if err != nil {
			return false, err
		}

		// 实例化商家对象
		var supplier_info model.SupplierUser
		err = json.Unmarshal(state, &supplier_info)
		if err != nil {
			return false, err
		}

		var new_supplier []model.Good

		// 实现遍历数据
		for _, v := range supplier_info.Goods {
			if v.Id == id { //如果id相同就代表是要删除的商品 则跳过
				continue
			}
			new_supplier = append(new_supplier, v) //将商品添加进来
		}

		//更新数据
		supplier_info.Goods = new_supplier

		//将数据json化
		bytes, err := json.Marshal(supplier_info)
		if err != nil {
			return false, err
		}

		err = ctx.GetStub().PutState("o_"+email, bytes)
		if err != nil {
			return false, err
		}

		//获取所有商品列表 删除商品
		var GOODS []model.Good
		goods_bytes, err := ctx.GetStub().GetState("goods")
		if err != nil {
			return false, err
		}

		err = json.Unmarshal(goods_bytes, &GOODS)
		if err != nil {
			return false, err
		}

		var new_goods []model.Good
		for i := 0; i < len(GOODS); i++ {
			if GOODS[i].Id == id {
				continue
			}
			new_goods = append(new_goods, GOODS[i])
		}

		//上传状态
		goodsJson, err := json.Marshal(new_goods)
		if err != nil {
			return false, err
		}

		err = ctx.GetStub().PutState("goods", goodsJson)
		if err != nil {
			return false, err
		}
		return true, nil
	} else { //代表商家不存在
		return false, errors.New("supplier user is not exists")
	}
}

// 实现商品编辑
func (m *MallContract) SupplierEditGoods(ctx contractapi.TransactionContextInterface, email, name, pic, desc, unit, price string, id string, stock int) (bool, error) {
	//判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return false, err
	}

	if exists { //代表商家存在
		//获取商家对象
		state, err := ctx.GetStub().GetState("o_" + email)
		if err != nil {
			return false, err
		}

		// 实例化商家对象
		var supplier_info model.SupplierUser
		err = json.Unmarshal(state, &supplier_info)
		if err != nil {
			return false, err
		}

		var data model.Good

		// 实现遍历数据
		for _, v := range supplier_info.Goods {
			if v.Id == id { //如果id相同就代表是要修改的商品
				v.Name = name
				v.Pic = pic
				v.Desc = desc
				v.Unit = unit
				v.Stock = stock
				v.Price = price

				data = v
			}
		}

		marshal, err := json.Marshal(data)
		if err != nil {
			return false, err
		}
		err = ctx.GetStub().PutState(id, marshal)

		//将数据json化
		bytes, err := json.Marshal(supplier_info)
		if err != nil {
			return false, err
		}

		err = ctx.GetStub().PutState("o_"+email, bytes)
		if err != nil {
			return false, err
		}

		//获取所有商品列表修改
		state, err = ctx.GetStub().GetState("goods")
		if err != nil {
			return false, err
		}

		var allGoods []model.Good
		err = json.Unmarshal(state, &allGoods)
		if err != nil {
			return false, err
		}

		for i := 0; i < len(allGoods); i++ {
			if allGoods[i].Id == id {
				allGoods[i] = data
			}
		}

		//上传状态
		bytes, err = json.Marshal(allGoods)
		if err != nil {
			return false, err
		}

		err = ctx.GetStub().PutState("goods", bytes)
		if err != nil {
			return false, err
		}
		return true, nil
	} else { //代表商家不存在
		return false, errors.New("supplier user is not exists")
	}
}

// 获取商家所有上架的商品
func (m *MallContract) SupplierGetGoods(ctx contractapi.TransactionContextInterface, email string) ([]model.Good, error) {
	//判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return nil, err
	}

	if exists { //代表商家存在
		//获取商家对象
		state, err := ctx.GetStub().GetState("o_" + email)
		if err != nil {
			return nil, err
		}

		// 实例化商家对象
		var supplier_info model.SupplierUser
		err = json.Unmarshal(state, &supplier_info)
		if err != nil {
			return nil, err
		}

		return supplier_info.Goods, nil
	} else { //代表商家不存在
		return nil, errors.New("supplier user is not exists")
	}
}

// 获取首页信息
func (m *MallContract) SupplierGetIndexData(ctx contractapi.TransactionContextInterface, email string) (model.SupplierIndexData, error) {
	//判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return model.SupplierIndexData{}, err
	}

	if exists { //代表商家存在
		//获取今日订单数
		now := time.Now()
		currentDate := now.Format("2006-01-02") //今天日期
		yesterday := time.Now().AddDate(0, 0, -1)
		yesterdayDate := yesterday.Format("2006-01-02") //昨天日期

		var dailyOrderNumber int = 0       //储存今日订单量
		var dailySalesTotal float64 = 0    //储存今日销售总额
		var previousSalesTotal float64 = 0 //昨日销售总额

		var completedOrder int = 0                   //已完成订单
		var shippedOrder int = 0                     //已发货订单
		var pendingDeliveryConfirmationOrder int = 0 //等待确认收货的订单
		var cancelledOrder int = 0                   //已取消的订单
		var pendingShipmentOrder int = 0             //等待发货的订单
		var outOfStockRegistration int = 0           //缺货登记

		var listedProduct int = 0           //上架商品
		var tightWarehouseInventory int = 0 //库房紧张
		var allProducts int = 0             //所有商品数量

		var dailyBrowse int = 0    //今日浏览
		var previousBrowse int = 0 //昨日浏览
		var monthBrowse int = 0    //该月浏览
		var allBrowse int = 0      //总浏览量

		//获取当前商家实例化
		state, err := ctx.GetStub().GetState("o_" + email)
		if err != nil {
			return model.SupplierIndexData{}, err
		}

		//获取实例
		var supplier_info model.SupplierUser
		err = json.Unmarshal(state, &supplier_info)
		if err != nil {
			return model.SupplierIndexData{}, err
		}

		//遍历orderer
		for _, v := range supplier_info.Orders { //商家订单
			if v.CreateTime == currentDate { //如果订单创建时间是今天的话则加入订单量
				dailyOrderNumber += 1
				float, err := strconv.ParseFloat(v.Amount, 64)
				if err != nil {
					return model.SupplierIndexData{}, err
				}
				dailySalesTotal += float
			}

			if v.CreateTime == yesterdayDate { //如果订单创建时间等于昨天的话
				float, err := strconv.ParseFloat(v.Amount, 64)
				if err != nil {
					return model.SupplierIndexData{}, err
				}
				previousSalesTotal += float
			}

			if v.Status == 2 { //代表该订单已完成
				completedOrder += 1
			}

			if v.Status == 1 { //代表该订单已发货
				shippedOrder += 1
			}

			if v.Status == 3 { //代表订单等待收货
				pendingDeliveryConfirmationOrder += 1
			}

			if v.Status == 4 { //代表订单已经取消
				cancelledOrder += 1
			}

			if v.Status == 0 { //等待发货的订单
				pendingShipmentOrder += 1
			}
		}

		//遍历商品表
		for _, g := range supplier_info.Goods { //遍历商品表
			if g.Stock == 0 { //代表该货缺货中
				outOfStockRegistration += 1
			}

			if g.Status == 1 { //代表该商品是上架的
				listedProduct += 1
			}

			if g.Stock < 10 { //代表该商品库房紧张
				tightWarehouseInventory += 1
			}

			//获取今日浏览
			for _, n := range g.Browses {
				if n.TimeDate == currentDate { //浏览日期等于今天
					dailyBrowse += n.Number
				}

				if n.TimeDate == yesterdayDate { //浏览日期等于昨天
					previousBrowse += n.Number
				}

				// 获取当前日期和月份
				now := time.Now()
				year, month, _ := now.Date()

				// 构建该月的第一天
				firstDay := time.Date(year, month, 1, 0, 0, 0, 0, now.Location())

				// 迭代获取该月中的所有日期
				for d := firstDay; d.Month() == month; d = d.AddDate(0, 0, 1) {
					if n.TimeDate == d.Format("2006-01-02") {
						monthBrowse += n.Number
					}
				}

				//获取所有订单
				allBrowse += n.Number
			}
		}

		allProducts = allProducts + len(supplier_info.Goods) //所有商品

		return model.SupplierIndexData{
			DailyOrderNumber:   dailyOrderNumber,
			DailySalesTotal:    fmt.Sprintf("%.2f", dailySalesTotal),
			PreviousSalesTotal: fmt.Sprintf("%.2f", previousSalesTotal),

			CompletedOrder:                   completedOrder,
			ShippedOrder:                     shippedOrder,
			PendingDeliveryConfirmationOrder: pendingDeliveryConfirmationOrder,
			CancelledOrder:                   cancelledOrder,
			PendingShipmentOrder:             pendingShipmentOrder,
			OutOfStockRegistration:           outOfStockRegistration,

			ListedProduct:           listedProduct,
			TightWarehouseInventory: tightWarehouseInventory,
			AllProducts:             allProducts,

			DailyBrowse:    dailyBrowse,
			PreviousBrowse: previousBrowse,
			MonthBrowse:    monthBrowse,
			AllBrowse:      allBrowse,
		}, nil
	} else { //代表商家不存在
		return model.SupplierIndexData{}, errors.New("supplier user is not exists")
	}
}

// 商家搜索订单
func (m *MallContract) SupplierSearchOrder(ctx contractapi.TransactionContextInterface, email string, OrderId string) (model.Order, error) {
	//判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return model.Order{}, err
	}

	if exists { //代表商家存在
		state, err := ctx.GetStub().GetState("o_" + OrderId)
		if err != nil {
			return model.Order{}, err
		}

		var body model.Order
		err = json.Unmarshal(state, &body)
		if err != nil {
			return model.Order{}, err
		}

		return body, nil

	}
	return model.Order{}, errors.New("supplier not exists")
}

// 获取订单主页数据
func (m *MallContract) SupplierOrderData(ctx contractapi.TransactionContextInterface, email string) ([]model.Order, error) {
	//判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return []model.Order{}, err
	}

	if exists { //代表商家存在
		state, err := ctx.GetStub().GetState("o_" + email) //获取商家端订单
		if err != nil {
			return []model.Order{}, err
		}

		var body model.SupplierUser //实例化商家对象
		err = json.Unmarshal(state, &body)
		if err != nil {
			return []model.Order{}, err
		}

		return body.Orders, nil

	}
	return []model.Order{}, errors.New("supplier not exists")
}

// 查看订单详情
func (m *MallContract) SupplierOrderDetail(ctx contractapi.TransactionContextInterface, email string, id string) (model.Order, error) {
	//判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return model.Order{}, err
	}

	if exists { //代表商家存在
		state, err := ctx.GetStub().GetState("o_" + id)
		if err != nil {
			return model.Order{}, err
		}

		var body model.Order
		err = json.Unmarshal(state, &body)
		if err != nil {
			return model.Order{}, err
		}

		return body, nil

	}
	return model.Order{}, errors.New("supplier not exists")
}

// 订单发货
func (m *MallContract) SupplierOrderDeliver(ctx contractapi.TransactionContextInterface, email string, orderId string, deliver string, deliverId string) (bool, error) {
	//判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return false, err
	}

	if exists { //代表商家存在
		state, err := ctx.GetStub().GetState(orderId)
		if err != nil {
			return false, err
		}

		//获取订单信息
		var body model.Order
		err = json.Unmarshal(state, &body)
		if err != nil {
			return false, err
		}

		//获取商家对象
		getState, err := ctx.GetStub().GetState("o_" + email)
		if err != nil {
			return false, err
		}
		var supplier model.SupplierUser
		err = json.Unmarshal(getState, &supplier)
		if err != nil {
			return false, err
		}

		//对订单进行发货
		body.LogisticsId = deliverId //物流单号
		body.Logistics = deliver     //物流方式
		operate := model.Operate{User: email, OperateTime: time.Now().Format("2006-01-02 15:04:05"), OrderStatus: 1, Remark: "订单已发货"}
		body.OperateInfo = append(body.OperateInfo, operate)

		bytes, err := json.Marshal(body)
		if err != nil {
			return false, err
		}

		//上传新的订单状态
		err = ctx.GetStub().PutState(orderId, bytes)
		if err != nil {
			return false, err
		}

		//更新商家里面订单信息
		for i := 0; i < len(supplier.Orders); i++ {
			if supplier.Orders[i].Id == orderId {
				supplier.Orders[i] = body
			}
		}
		//上传状态
		marshal, err := json.Marshal(supplier)
		if err != nil {
			return false, err
		}

		//上传
		err = ctx.GetStub().PutState("o_"+email, marshal)
		if err != nil {
			return false, err
		}

		//获取所有订单 然后更新订单数据
		state, err = ctx.GetStub().GetState("orders")
		if err != nil {
			return false, err
		}
		var Orders []model.Order
		err = json.Unmarshal(state, &Orders)
		if err != nil {
			return false, err
		}

		for i := 0; i < len(Orders); i++ {
			if Orders[i].Id == orderId {
				Orders[i] = body
			}
		}

		//上传
		marshal, err = json.Marshal(Orders)
		if err != nil {
			return false, err
		}

		err = ctx.GetStub().PutState("orders", marshal)
		if err != nil {
			return false, err
		}
		return true, nil
	}
	return false, errors.New("supplier not exists")
}

// 商家更换头像
func (m *MallContract) SupplierChangeHead(ctx contractapi.TransactionContextInterface, email string, pic string) (bool, error) {
	//判断商家是否存在
	exists, err := m.SupplerExists(ctx, email)
	if err != nil {
		return false, err
	}

	if exists { //代表商家存在
		//获取商家对象
		var supplier model.SupplierUser
		state, err := ctx.GetStub().GetState("o_" + email)
		if err != nil {
			return false, err
		}
		err = json.Unmarshal(state, &supplier)
		if err != nil {
			return false, err
		}

		//更换图片
		supplier.Head = pic

		//marshal supplier
		marshal, err := json.Marshal(supplier)
		if err != nil {
			return false, err
		}

		//上传状态
		err = ctx.GetStub().PutState("o_"+email, marshal)
		if err != nil {
			return false, err
		}

		//在商家列表实现更换商家信息
		var supplierList []model.SupplierUser
		state, err = ctx.GetStub().GetState("suppliers")
		if err != nil {
			return false, err
		}

		err = json.Unmarshal(state, &supplierList)
		if err != nil {
			return false, err
		}

		for i := 0; i < len(supplierList); i++ {
			if supplierList[i].Email == email {
				supplierList[i] = supplier
			}
		}

		//将信息上传
		marshal, err = json.Marshal(supplierList)
		if err != nil {
			return false, err
		}

		err = ctx.GetStub().PutState("suppliers", marshal)
		if err != nil {
			return false, err
		}

		return true, nil
	}
	return false, errors.New("supplier not exists")
}
